﻿#if !WINDOWS_PHONE && !SILVERLIGHT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework;
#endif

namespace Brain
{
#if !SILVERLIGHT  && !WINDOWS_PHONE && !MONOGAME
    /// <summary>
    /// This class won't work on Windows Phone 7 and Silverlight. On Windows
    /// it won't render anything, in the future this will make a Box World Object
    /// </summary>
    public class XboxAvatar : WorldObject
    {
        public AvatarDescription Description;
        public AvatarRenderer Renderer;

        public IAvatarAnimation IAvatarAnimation;

        private bool loaded = false;
        public bool Loaded
        {
            get { return loaded; }
            set
            {
                if (value && !loaded)
                {
                    if (OnLoaded != null)
                    {
                        OnLoaded(this);
                    }
                    loaded = value;
                }
            }
        }

        /// <summary>
        /// Different from the WhenGet passed on the Constructor,
        /// used by the Engine's Custom Sysetmes
        /// </summary>
        public event SetXboxAvatar OnLoaded;

        public bool Loop { get; set; }

        public XboxAvatar()
        {
            Description = AvatarDescription.CreateRandom();
            Renderer = new AvatarRenderer(Description);
            Loaded = true;
        }
        public XboxAvatar(AvatarDescription description)
        {
            Description = description;
            Renderer = new AvatarRenderer(Description);
            Loaded = true;
        }
        private SetXboxAvatar WhenGet;
        public XboxAvatar(Gamer Gamer, SetXboxAvatar WhenGet)
        {
            this.WhenGet = WhenGet;
            AvatarDescription.BeginGetFromGamer(Gamer, IAResult, null);
        }
        public virtual void IAResult(IAsyncResult Result)
        {
            Description = AvatarDescription.EndGetFromGamer(Result);
            Renderer = new AvatarRenderer(Description, false);
            Loaded = true;

            if (WhenGet != null)
            {
                WhenGet(this);
            }
        }
    }
#endif
}
